<?php
namespace common\actions;
use Yii;
use yii\helpers\ArrayHelper;
use kucha\ueditor\UEditorAction;

class UEditorActionI extends UEditorAction
{
    public function init()
    {
        parent::init();
        $_config['imageRoot'] = \Yii::$app->params["attach.image.path"];
        $_config['scrawlRoot'] = \Yii::$app->params["attach.image.path"];
        $_config['videoRoot'] = \Yii::$app->params["attach.image.path"];
        $_config['fileRoot'] = \Yii::$app->params["attach.image.path"];

        //load config file
        $this->config = ArrayHelper::merge($this->config,$_config);
    }
    /**
     * 处理action
     */
    protected  function handleAction()
    {
        $action = Yii::$app->request->get('action');
        switch ($action) {
            case 'config':
                $result = $this->config;
                /* 输出结果 */

                break;

            /* 上传图片 */
            case 'uploadimage':
                /* 上传涂鸦 */
            case 'uploadscrawl':
                /* 上传视频 */
            case 'uploadvideo':
                /* 上传文件 */
            case 'uploadfile':

                $result = UEditorAction::actionUpload();
                //处理返回的URL
                if (substr($result['url'], 0, 1) != '/') {
                    $result['url'] = '/' . $result['url'];
                }
                $result['url'] = $result['url'];//Yii::getAlias($this->config['imageUrlPrefix'].$result['url']);
                break;
            /* 列出图片 */
            case 'listimage':
                /* 列出文件 */
            case 'listfile':
                $result = UEditorAction::actionList();
                break;

            /* 抓取远程文件 */
            case 'catchimage':
                $result = UEditorAction::actionCrawler();
                break;

            default:
                $result = [
                    'state' => '请求地址出错'
                ];
                break;
        }
      return $result;
    }
}